package offertest.singleton;

public class Lazy {
    private static volatile Lazy instance = null;

    private Lazy() {
        if (instance != null) {
            throw new RuntimeException("Instance already exists!");
        }
    }

    public static Lazy getInstance() {
        if (instance == null) { // 第一次检查
            synchronized (Lazy.class) {
                if (instance == null) { // 第二次检查
                    instance = new Lazy();
                }
            }
        }
        return instance;
    }
}